<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>


                    <div class="form-horizontal field-attaches" enctype="multipart/form-data">
                        <div class="form-group">
                            <label class="col-sm-3 control-label no-padding-right" for="attaches">资料</label>
                            <div class="col-sm-5">
                                <button type="button" id="attachesupload" class="form-control border-input" >上传资料</button>
                            </div>
                           <input type="hidden" id="attaches" class="form-control" >

                        </div>
                    </div>
                    <div class="form-horizontal field-meeting-attaches" >
                        <div class="form-group"><label class="col-sm-3 control-label no-padding-right" for="meeting-content"></label>
                        <div class="col-sm-5">
                            <ul class="list-group" id="piclist">
                              <!--  <li class="list-group-item">Cras justo odio<button type="button" style="float:right;" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-remove-sign" aria-hidden="true"></span></button></li>-->
                                
                            </ul>
                        </div>
                    </div>


<script src="http://dangjian.e23.cn/backend/web/js/jquery-2.1.4.js"></script>
<script src="http://dangjian.e23.cn/backend/web/assets/d27dc29e/js/ajaxupload.js"></script>
<script>
        new AjaxUpload($('#attachesupload'), {
            action: '/backend/web/upload/upload?action=uploadimage',
            name: 'upfile',
            data:{
                'userid':'1',
                'catid':'0',
                'module':'meeting'
            },
            onSubmit: function(file, ext) {
               
            },
            onChange: function(file, ext) {
                
            },
            onComplete: function(file, response) {

                // console.log(file);
                console.log(response);
            
                var attaches_str=$('#attaches').val();
                var attaches_array=attaches_str.split(",");
                var filereturn =response.split(",");
              
                if($.inArray(filereturn[0], attaches_array)<0)
                {
                    $('#piclist').append('<li val="'+filereturn[0]+'" class="list-group-item">'+file+'<img src="'+filereturn[1]+'" /><button style="float:right;" type="button" class="btn btn-default btn-xs delattach" >X</button></li>');
                    
                    attaches_array.push(filereturn[0]);
                   
                    var str=attaches_array.join(',');
                    // console.log(str);
                    $('#attaches').val(str);
                }
                else
                {
                   

                }
            
            }
 });


 $('#piclist').on('click','.delattach',function(){
 
    var val=$(this).parent().attr('val');
    $(this).parent().remove();//
    var attaches_str=$('#attaches').val();//获取附件的值
    var attaches_array=attaches_str.split(",");//字符串转换为数组
    attaches_array.splice($.inArray(val,attaches_array),1);//从数组中移除
    var str=attaches_array.join(',');//数组转换字符串
    $('#attaches').val(str);//字符串赋值
    console.log('删除成功');
 });

</script>
	
</body>
</html>